﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TuongLaiDangCho.DTO;
using System.Data.OleDb;
using System.Data;

namespace TuongLaiDangCho.DAO
{
    class DanhNgonDAO
    {
        public static DataTable LoadDanhNgon()
        {
            string sql = "Select * From DANHNGON";
            OleDbConnection cn = DataProvider.OpenCn();
            OleDbDataAdapter da = new OleDbDataAdapter(sql, cn);
            DataTable dt = new DataTable();
            da.Fill(dt);
            cn.Close();
            return dt;
        }
        public static void InsertDanhNgon(DanhNgonDTO danhngon)
        {
            string sql = "Insert Into DANHNGON(NgayDang,NoiDung,TacGia) values(#" + danhngon.Date.ToShortDateString() + "#,'" + danhngon.NoiDung + "','" + danhngon.TacGia + "')";
            OleDbConnection cn = DataProvider.OpenCn();
            OleDbCommand cm = new OleDbCommand(sql, cn);
            cm.ExecuteNonQuery();
            cn.Close();
        }

        public static void UpdateDanhNgon(DanhNgonDTO danhngon)
        {
            string sql = "Update DANHNGON set NoiDung='" + danhngon.NoiDung + "' , NgayDang=#" +danhngon.Date.ToShortDateString()+ "#, TacGia='" + danhngon.TacGia + "' where ID=" + danhngon.Id.ToString() + "";
            OleDbConnection cn = DataProvider.OpenCn();
            OleDbCommand cm = new OleDbCommand(sql, cn);
            cm.ExecuteNonQuery();
            cn.Close();
        }

        public static void DeleteDanhNgon(DanhNgonDTO danhngon)
        {
            string sql = "Delete From DANHNGON where ID=" + danhngon.Id.ToString() + "";
            OleDbConnection cn = DataProvider.OpenCn();
            OleDbCommand cm = new OleDbCommand(sql, cn);
            cm.ExecuteNonQuery();
            cn.Close();
        }
    }
}
